#include "QAddCategoryDialog.h"

QAddCategoryDialog::QAddCategoryDialog(QWidget *parent)
    : QDialog(parent)
{
    setGeometry(200,200,260,60);
    initWidget();
    initConnect();

}

QAddCategoryDialog::~QAddCategoryDialog(){


}

void QAddCategoryDialog::initWidget(){

    mNameLabel = new QLabel(this);
    mNameLabel->setGeometry(10,10,100,20);
    mNameLabel->setText("CategoryName : ");

    mName = new QLineEdit(this);
    mName->setGeometry(110,10,140,20);

    mSaveButton = new QPushButton(this);
    mSaveButton->setGeometry(10,35,120,20);
    mSaveButton->setText("Save");

    mCancelButton = new QPushButton(this);
    mCancelButton->setGeometry(130,35,120,20);
    mCancelButton->setText("Cancel");
}

void QAddCategoryDialog::initConnect(){

    connect(mCancelButton,SIGNAL(clicked()),this,SLOT(close()));
    connect(mSaveButton,SIGNAL(clicked()),this,SLOT(saveCategorySlot()));

    connect(mCancelButton,SIGNAL(clicked()),this,SLOT(reject()));
    connect(mSaveButton,SIGNAL(clicked()),this,SLOT(accept()));
}

void QAddCategoryDialog::saveCategorySlot(){

    QSqlQuery query;
    query.prepare("insert into category (name) values (?) ");
    query.addBindValue(mName->text());
    query.exec();

    this->close();


}
